package com.cms.action;

import java.util.List;

import com.action.DefaultAction;
import com.cms.manager.CategoryManager;
import com.cms.model.Category;


/**   
 *   
 * @author zhanghusong   
 */
public class CategoryAction extends DefaultAction {

	private static final long serialVersionUID = 1L;
	List<Category> list;
	Category model;
	
	public CategoryAction()
	{
	}
	String type="";
	String msg="";
	public String list()
	{
		list = CategoryManager.getInstance().getCategorys();
		return SUCCESS;
	}
	public String show()
	{
		if(type.equals("upd"))
		{
			model = CategoryManager.getInstance().getCategory(model.getId());
		}
		else
		{
			model  = new Category();
			model.setId(-1);
		}
		list = CategoryManager.getInstance().getCategorys();
		return SUCCESS;
	}
	public String save()
	{
		if(type.equals("add"))
		{
			model.setCreateUser(getAdminLoginName());
			if(CategoryManager.getInstance().saveCpInfo("insert", model))
				msg = "类别管理：添加成功";
			else
				msg = "类别管理：添加失败！请重新添加！";
		}
		else if(type.equals("update"))
		{
			if(CategoryManager.getInstance().saveCpInfo("update", model))
				msg = "类别管理：更新成功！";
			else
				msg = "类别管理：更新失败！请重新更新！";
			type = "upd";
		}
		else if(type.equals("del"))
		{
			if(CategoryManager.getInstance().saveCpInfo("delete", model))
				msg = "类别管理：删除成功！";
			else
				msg = "类别管理：删除失败！请重新删除！";
		}
		return SUCCESS;
	}
	public List<Category> getList() {
		return list;
	}
	public void setList(List<Category> list) {
		this.list = list;
	}
	public Category getModel() {
		return model;
	}
	public void setModel(Category model) {
		this.model = model;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	
	
	
}
